﻿<!--
 * @Descripttion: 
 * @version: v1
 * @Author: Terry
 * @Date: 2020-06-04 17:18:56
 * @LastEditors: Terry
 * @LastEditTime: 2023-12-09 14:30:53
-->
<template>
  <div>
      <el-form :model="loginForm" :rules="rules" ref="loginForm">
          <el-form-item prop="account" :label="$t('platform.auth.accountLabel')" class="m-b-5 text-white">
            <el-input
              v-model="loginForm.account"
              :placeholder="$t('platform.auth.accountTips')"
            ></el-input>
          </el-form-item>
          <el-form-item prop="password" class="m-b-5" :label="$t('platform.auth.passwordLabel')">
            <el-input
              type="password"
              v-model="loginForm.password"
              autocomplete="off"
              :placeholder="$t('platform.auth.passwordTips')"
            ></el-input>
          </el-form-item>
          <el-form-item class="m-b-5" >
            <el-button class="float-right " type="text" @click="toPage('register')">{{$t('platform.auth.notAccount')}}</el-button>
            <el-button class=" " type="text" @click="toPage('forget')">{{$t('platform.auth.forget')}}</el-button>
        </el-form-item>
          <el-form-item class="m-b-5">
            <el-button
              type="primary"
              class="w-100"
              @click="login"
              >{{$t('platform.auth.loginBtn')}}</el-button
            >
          </el-form-item>
        </el-form>
  </div>
</template>
<script>
import { pcLogin } from "../api/auth"
export default {
  data() {
    return {
     
      loginForm: {
        account: "",
        password: ""
      },
      rules: {
        account: [
          { required: true, message: this.$t("platform.auth.accountRequired"), trigger: "blur" }
        ],
        password: [
          { required: true, message: this.$t("platform.auth.pwdRequired"), trigger: "blur" },
          { min: 6, max: 16, message: this.$t("platform.auth.pwdLen"), trigger: "blur" }
        ]
      },
    };
  },
  methods: {
    toPage(name){
     this.$router.push({ 'name': name });
    },
    login(){
       // 表单判断
        this.$refs.loginForm.validate((valid) => {
            if (valid) {
                var load = this.loading();
                pcLogin(this.loginForm).then(res=>{
                      sessionStorage.setItem("auxfaceToken", res.data.token);//token
                      sessionStorage.setItem("uuid", res.data.uuid);//用户uuid
                      sessionStorage.setItem("nickName", res.data.info.nickName); //名称
                      sessionStorage.setItem("avatarUrl", res.data.info.avatarUrl); //头像
                      sessionStorage.setItem("myCorpCode", res.data.corpCode); //企业
                      this.$router.push({ name: process.env.VUE_APP_HOME });
                }).finally(()=>{
                    load.close();
                })
            }
        }); 
    }
  },created(){
        var that = this;
        document.onkeydown = function(e){
          if(e.key =='Enter'){
            that.login();
          }
        }
    }
};
</script>
